

package com.netcracker.ui.command;

import com.netcracker.entity.Genre;
import com.netcracker.util.service.GenreService;
import com.netcracker.util.service.ServiceFacade;
import com.netcracker.util.service.exception.DataTransmittingException;
import com.netcracker.util.service.exception.NullDataException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GetAllGenresCommand implements Command {
    private static final Logger LOGGER = LoggerFactory.getLogger(GetAllGenresCommand.class);
    private final ServiceFacade serviceFacade;

    public GetAllGenresCommand(ServiceFacade serviceFacade) {
        this.serviceFacade = serviceFacade;
    }

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) {
        GenreService genreService = serviceFacade.getGenreService();
        List<Genre> genres = null;
        try {
            genres = genreService.getAllGenres();
        } catch (DataTransmittingException ex) {
            request.setAttribute("error", "Ошибка обращения к БД.");
            LOGGER.error("DB error: ", ex);
        } catch (NullDataException ex) {
            request.setAttribute("error", "Жанров не найдено.");
        }
        request.setAttribute("genres", genres);
        return "AdminGenres.jsp";
    }
    
    
}
